<template>
	<view class="page">
		<view class="info_box">
			<view class="info_box_base">
				<view class="info_box_base_title" style="font-weight: bold;">站点信息</view>
				<view class="info_box_base_item">所属地区：{{baseInfo.region}}</view>
				<!-- <view class="info_box_base_item">站点编号：{{baseInfo.site_number}}</view> -->
				<view class="info_box_base_item" v-if="baseInfo.operators == 1">运营商：中国移动</view>
				<view class="info_box_base_item" v-if="baseInfo.operators == 2">运营商：中国电信</view>
				<view class="info_box_base_item" v-if="baseInfo.operators == 3">运营商：中国联通</view>
				<view class="info_box_base_item">站点名称：{{baseInfo.title}}</view>
				<view class="info_box_base_item">站点地址：{{baseInfo.site_address}}</view>
				<view class="info_box_base_item">联系人及电话：{{baseInfo.contacts}} {{baseInfo.phonetel}}</view>
				<view class="info_box_base_item">工单说明：<text class="base_item_dd">{{baseInfo.work_orderdesc}}</text></view>
				<view class="info_box_base_item" style="color: red;" v-if="baseInfo.status == 3">拒绝原因：<text class="base_item_dd">{{baseInfo.rejection}}</text></view>
				<view class="info_box_base_item">创建时间：{{baseInfo.create_time}}</view>
			</view>

			<view class="info_box_base">
				<view class="info_box_base_title" style="font-weight: bold;">工程协调<text style="color: red;">*</text></view>
				<view class="gcxt_b_wy">
					<view>物业(业主)：</view>
					<view class="gcxt_b_wy_radio">
						<u-radio-group @change="chooseWy" v-model="gckcParasms.property">
							<u-radio shape="circle" name="1" style="margin-right: 20rpx;" iconSize="12px" labelSize="13"
								label="同意"></u-radio>
							<u-radio shape="circle" name="2" style="margin-right: 20rpx;" iconSize="12" labelSize="13"
								label="不同意"></u-radio>
							<u-radio shape="circle" name="3" iconSize="12" labelSize="13" label="待定"></u-radio>
						</u-radio-group>
					</view>
				</view>
				<view class="gcxt_b_wy_reason">
					<text sty>不同意/待定原因：</text>
					<u--input placeholder="请输入具体原因" v-model="gckcParasms.disagree" border="none"></u--input>
				</view>
			</view>

			<view class="info_box_base">
				<view class="info_box_base_title" style="font-weight: bold;">设计安装条件<text style="color: red;" v-if="gckcParasms.property == 1">*</text></view>
				<view class="gcxt_b_wy">
					<u-checkbox-group @change="chooseTj" v-model="gckcParasms.designinstallcond_id"
						style="width: 690rpx;flex-wrap: wrap;white-space: nowrap;overflow: hidden;text-overflow: ellipsis;">
						<u-checkbox size="13" v-for="(item,index) in sjanlist" style="width: 33%;margin-bottom: 20rpx;"
							labelSize="13" :name="item.id" :label="item.title"></u-checkbox>
					</u-checkbox-group>
				</view>
				<view class="gcxt_b_wy_reason">
					<text sty>其他说明<text style="color: red;" v-if="gckcParasms.property == 1">*</text>：</text>
					<u--input placeholder="请输入具体说明" v-model="gckcParasms.other_instructions" border="none"></u--input>
				</view>
			</view>

			<view class="btn" @click="next">下一步</view>
		</view>
	</view>
</template>

<script>
	import {
		forEach
	} from '../../js_sdk/luch-request/luch-request/utils';
	import {
		api,
		apiBaseUrl,
		http
	} from '@/config/common.js'
	export default {
		data() {
			return {
				baseInfo: {},
				id: '',
				isdd: false,
				sjanlist: [],
				gckcParasms: {
					property: '', //物业（业主）（1同意，2不同意，3待定）
					disagree: '', //不同意/待定原因
					designinstallcond_id: [], //设计安装条件id
					other_instructions: '', //其他说明
				}
			}
		},
		components: {},
		filters: {},
		mounted() {},
		onLoad(e) {
			this.id = e.id
			this.getSjAzTj()
			this.getBaseInfo()
			this.lookInfo()
		},
		onShow() {},
		onPageScroll(e) {},
		beforeDestroy() {},
		methods: {
			//站点信息显示
			getBaseInfo() {
				uni.showLoading({})
				api.post('/api/shop/kanc_site_information', {
					survey_id: this.id
				}).then(res => {
					let rst = res.data
					uni.hideLoading()
					if (rst.code == 1) {
						this.baseInfo = rst.data
					}

				}).catch(err => {
					uni.hideLoading()
				})
			},
			//查找录入信息
			lookInfo() {
				uni.showLoading({})
				api.post('api/shop/submit_siteinfor', {
					survey_id: this.id,
					type: 2
				}).then(res => { 
					let rst = res.data 
					uni.hideLoading()
					if (rst.code == 1) {
						rst.data.property = rst.data.property.toString()
						rst.data.designinstallcond_id = rst.data.designinstallcond_id?rst.data.designinstallcond_id.map(item => parseInt(item,10)):[]
						this.gckcParasms = rst.data
					}

				}).catch(err => {
					uni.hideLoading()
				})
			},
			//设计安装条件
			getSjAzTj() {
				uni.showLoading({})
				api.post('/api/shop/survey_siteinfo_designinstallcond', {}).then(res => {
					let rst = res.data
					uni.hideLoading()
					if (rst.code == 1) {
						this.sjanlist = rst.data
					}

				}).catch(err => {
					uni.hideLoading()
				})
			},
			//选择业务业主
			chooseWy(e) {
				this.gckcParasms.property = e
			},
			//选择设计安装条件
			chooseTj(e) {
				let sjanlist = this.sjanlist
				let temp_rst = []
				for (let i = 0; i < e.length; i++) {
					for (let j = 0; j < sjanlist.length; j++) {
						if (sjanlist[j]['id'] == e[i]) {
							temp_rst.push(sjanlist[j])
						}
					}
				}
				for (let jj = 0; jj < temp_rst.length; jj++) {
					this.isdd = false
					if (temp_rst[jj]['title'] == '待定') {
						this.isdd = true
						break;
					}
				}
				this.designinstallcond_ids = e
			},
			next() {
				let rst = this.gckcParasms 
				if (!rst.property) {
					uni.$u.toast("请选择工程协调物业选项")
					return;
				}
				if ((rst.property == 2 || rst.property == 3) && !rst.disagree) {
					uni.$u.toast("请填写不同意/待定的原因")
					return;
				}
				if (rst.property == 1) {
					if (rst.designinstallcond_id.length <= 0){
						uni.$u.toast("请选择设计安装条件")
						return;
					}
					if (!rst.other_instructions){
						uni.$u.toast("请填写其他说明")
						return;
					}
				}
				

				
				uni.showLoading({})
				api.post('api/shop/submit_siteinfor', {
					survey_id: this.id,
					property: rst.property,
					disagree: rst.disagree,
					other_instructions: rst.other_instructions,
					designinstallcond_id: rst.designinstallcond_id.join(','),
					type: 1,
					sjtj_is_dd:this.isdd
				}).then(res => {
					let rsttt = res.data
					uni.hideLoading()
					if (rsttt.code == 1) {
						if (this.isdd || (rst.property == 2 || rst.property == 3)) {
							uni.navigateTo({
								url: '/pages/kcsj/index'
							})
						} else {
							uni.navigateTo({
								url: '/pages/kcsj/kcsj?id=' + this.id
							})
						}

					} else {
						uni.$u.toast(rsttt.msg)
					}
				}).catch(err => {
					uni.hideLoading()
				})


			}
		}
	};
</script>

<style scoped>
	.base_item_dd{
		word-wrap: break-word;
		overflow-wrap: break-word;
		white-space: normal;
		width: 80%;
	}
	.btn {
		width: 500rpx;
		height: 80rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		margin: 0 auto;
		margin-top: 90rpx;
		background-color: rgb(70, 179, 255);
		color: #fff;
		border-radius: 40rpx;
		font-size: 32rpx;
	}

	::v-deep .uni-input-input {
		font-size: 26rpx;
	}

	::v-deep .uni-input-placeholder {
		font-size: 26rpx;
	}

	.gcxt_b_wy_reason {
		display: flex;
		flex-direction: row;
		align-items: center;
	}

	.gcxt_b_wy {
		display: flex;
		flex-direction: row;
		align-items: center;
		margin: 20rpx 0;
	}

	.info_box_base {
		border: 1px solid rgb(235, 229, 229);
		padding: 20rpx;
		font-size: 26rpx;
		margin-top: 20rpx;
	}

	.info_box_base_item {
		word-wrap: break-word;
		overflow-wrap: break-word;
		white-space: normal;
		line-height: 45rpx;
		width: 100%;
	}

	.info_box {
		width: 710rpx;
		margin: 0 auto;

	}

	page {
		background-color: #fff;
	}
</style>